﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.OleDb;

public partial class delete_staff : System.Web.UI.Page
{
    OleDbConnection conx;

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            String con = "Provider=MSDAORA;Data Source=orcl;Password=oracle;User ID=pearl";//"DSN=orcl;Driver={Microsoft ODBC for Oracle};UID=system;PWD=password;SERVER=localhost;";
            conx = new OleDbConnection(con);
            conx.Open();

            

            if (conx.State == ConnectionState.Open)
            {   
               string pk = "";
               foreach( GridViewRow row in GridView1.Rows ){
                   CheckBox cbd = (CheckBox)row.FindControl("check_box_delete");
                   if (cbd != null && cbd.Checked) {
                       pk = GridView1.Rows[row.RowIndex].Cells[2].Text;

                       OleDbCommand ODC = new OleDbCommand("DELETE FROM STAFFS WHERE STAFF_ID = '"+pk+"'", conx);
                       ODC.ExecuteNonQuery();
                       Label1.Text = "Delete Successful";
                   }
               }
               GridView1.DataBind();
                   
            }
            else
                Label1.Text = "Oracle Connect Failed";
        }

        catch(Exception ex)
        {
            Label1.Text = ex.Message + "<br />" + ex.StackTrace;
        }

        finally
        {
            conx.Close();
            conx = null;
        }
    }
    protected void Back_Click(object sender, EventArgs e)
    {
        Response.Redirect("staff.aspx");
    }
}